﻿using Ldt.CommonCapacitySupport.Business;
using Ldt.CommonCapacitySupport.Business.Model;
using LdtJudge.DataEngine.CallInterface;
using LdtJudge.DataEngine.CallInterface.ConfigManager;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Ldt.CommonCapacitySupport.Controllers
{
    /// <summary>
    /// 要素处理能力
    /// </summary>
    [Route("elementhandlecapacity/v1")]
    [ApiController]
    public class ElementHandleCapacityController : Controller
    {
        /// <summary>
        /// 配置对象处理类
        /// </summary>
        private IConfigRetrieval _configRetrieval { get; }
        /// <summary>
        /// http请求对象
        /// </summary>
        private LdtCommonLibraryHttp.HttpHelper _httpHelper { get; }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="configRetrieval">配置中心对象</param>
        /// <param name="httpHelper">http请求对象</param>
        public ElementHandleCapacityController(IConfigRetrieval configRetrieval, LdtCommonLibraryHttp.HttpHelper httpHelper)
        {
            _configRetrieval = configRetrieval;
            _httpHelper = httpHelper;
        }
        /// <summary>
        /// 执行设定
        /// </summary>
        /// <param name="anjid">唯一ID</param>
        /// <param name="typename">类型名称</param>
        private void SetTaskDataInfo(string anjid, string typename)
        {
            //将日志放入同步数据的文件夹下
            System.Runtime.CallContext.SetData("baseDirectory", _configRetrieval.GetLogPath());
            System.Runtime.CallContext.SetData("typename", typename.ToLower());
            System.Runtime.CallContext.SetData("systemplatform", ConfigManagerHandle.PlatFormName.wordparse_commoncapacitysupport);
            System.Runtime.CallContext.SetData("identifier", anjid.ToLower());
            System.Runtime.CallContext.SetData("customid", System.Threading.Thread.CurrentThread.ManagedThreadId.ToString());//当前标识ID
        }
        /// <summary>
        /// 分人员要素比对
        /// </summary>
        /// <param name="model">人员要素信息</param>
        /// <returns></returns>
        [HttpPost]
        [Route("comparepersonalelement")]
        public ReturnMessageModel ComparePersonalElement([FromBody] ComparePersonElementModel model) 
        {
            // 返回结果类
            ReturnMessageModel returnMessage = new ReturnMessageModel();
            Result res = new Result();
            returnMessage.result = res;
            // 开始比对人员要素
            ComparePersonElementHandle comparePersonElementHandle = new ComparePersonElementHandle();
            ComparePersonElementReturnModel compareResult = comparePersonElementHandle.CompareElement(model);
            res.code = "1";
            res.message = "";
            returnMessage.body = compareResult;
            return returnMessage;

        }
        /// <summary>
        /// 合并要素
        /// </summary>
        /// <param name="model">要素信息</param>
        /// <returns></returns>
        [HttpPost]
        [Route("mergeelementcontent")]
        public ReturnMessageModel MergeElementContent([FromBody] MergeElementModel model) 
        {
            // 返回结果类
            ReturnMessageModel returnMessage = new ReturnMessageModel();
            Result res = new Result();
            returnMessage.result = res;

            ComparePersonElementHandle comparePersonElementHandle = new ComparePersonElementHandle();
            MergeElementResultModel mergeElementResult = comparePersonElementHandle.MergerElement(model);
            res.code = "1";
            res.message = "";//JsonConvert.SerializeObject(mergeElementResult);
            returnMessage.body = mergeElementResult;
            return returnMessage;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        [HttpPost]
        [Route("mergexmlcontent")]
        public ReturnMessageModel MergeXMLContent([FromBody] MergeXmlModel model) 
        {
            ReturnMessageModel returnMessage = new ReturnMessageModel();
            Result res = new Result();
            returnMessage.result = res;
            try
            {
                ComparePersonElementHandle comparePersonElementHandle = new ComparePersonElementHandle();
                returnMessage.body = comparePersonElementHandle.MergerXml(model);
                res.code = "1";
            }
            catch (Exception ex)
            {
                res.code = "0";
                res.message = ex.ToString();
            }
            
            return returnMessage;
        }



    }
}
